// import { DECREMENT, INCREMENT } from '../const/conter.const'

// const initlialState = {
// 	count: 0,
// }

// export default (state = initlialState, action) => {
// 	let { type, payload } = action
// 	switch (type) {
// 		case INCREMENT:
// 			return {
// 				...state,
// 				count: state.count + payload,
// 			}
// 		case DECREMENT:
// 			return {
// 				...state,
// 				count: state.count - payload,
// 			}
// 		default:
// 			return state
// 	}
// }

// 使用 redux-actions
import { handleActions as createReducer } from 'redux-actions'
import { increment, decrement } from '../actions/conter.action'

const initlialState = {
	count: 0,
}

// 参数被自动添加到了action中 ，可以通过action.payload获取
const handleIncrement = (state, action) => ({
	count: state.count + action.payload,
})

const handleDecrement = (state, action) => ({
	count: state.count - action.payload,
})

// 第二个参数是默认值
export default createReducer(
	{
		[increment]: handleIncrement,
		[decrement]: handleDecrement,
	},
	initlialState
)
